package com.example.day01;

import androidx.appcompat.app.AppCompatActivity;
import androidx.recyclerview.widget.LinearLayoutManager;
import androidx.recyclerview.widget.RecyclerView;

import android.os.Bundle;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;

import com.example.day01.adapter.XiaAdapter;
import com.example.day01.bean.XiaBean;
import com.example.day01.contract.LoginContract;
import com.example.day01.model.LoginModel;
import com.example.day01.presenter.LoginPresenter;
import com.example.mvp.view.BaseActivity;
import com.google.gson.Gson;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;

import java.util.ArrayList;
import java.util.List;

import javax.xml.transform.sax.TemplatesHandler;

public class XiaActivity extends BaseActivity<LoginPresenter> implements LoginContract.XiaView {

    private SmartRefreshLayout smart;
    private RecyclerView rv;
    private List<XiaBean.DataBean>list=new ArrayList<>();
    private XiaAdapter xiaAdapter;
    LoginPresenter loginPresenter;


    @Override
    protected void onStart() {
        super.onStart();
        loginPresenter.Xiadata();
    }

    @Override
    public void XiaMed(String json) {
        Log.e("xxr", "XiaMed: "+json );
        if(json!=null){
            XiaBean xiaBean = new Gson().fromJson(json, XiaBean.class);
            List<XiaBean.DataBean> data = xiaBean.getData();
            list.addAll(data);
            xiaAdapter.notifyDataSetChanged();
        }

    }

    @Override
    public int bindLayout() {
        return R.layout.activity_xia;
    }

    @Override
    public void initData() {

    }

    @Override
    public void initView() {
        smart = (SmartRefreshLayout) findViewById(R.id.smart);
        rv = (RecyclerView) findViewById(R.id.rv);
        xiaAdapter=new XiaAdapter(R.layout.xia_layout,list);
        rv.setAdapter(xiaAdapter);
        LinearLayoutManager linearLayoutManager = new LinearLayoutManager(this);
        rv.setLayoutManager(linearLayoutManager);

        //添加头
        View inflate = LayoutInflater.from(this).inflate(R.layout.lhead_ayout, null);
        xiaAdapter.addHeaderView(inflate);

    }

    @Override
    public void inject() {
         loginPresenter= new LoginPresenter(new LoginModel(), this);

    }
}
